package HighMethod02;

/**
 * 求数组的全排列
 * 用到：”排列树“
 */
public class test01 {

    public static void Perm(int[] ar, int k, int m) {
        if (k == m) {
            for (int i = 0; i <= m; i++) {
                System.out.print(ar[i] + " ");
            }
            System.out.println();

        } else {
            for (int j = k; j <= m; j++) {
                Swap_Ar(ar,j,k);
                Perm(ar,k+1,m);
                Swap_Ar(ar,j,k);
            }
        }

}

    private static void Swap_Ar(int[] ar, int j, int k) {
        int tmp  = ar[j];
        ar[j] = ar[k];
        ar[k] = tmp;
    }


    public static void main(String[] args) {
        int arr[] = {1,2,3,4};
        Perm(arr,0,arr.length-1);

    }
}
